package com.ujs.edu.demo.dao;

import com.ujs.edu.demo.dataobject.BcAdmin;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
@Mapper
public interface BcAdminMapper {
    @Delete({
        "delete from bc_admin",
        "where admin_id = #{adminId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer adminId);

    @Insert({
        "insert into bc_admin (admin_id, username, ",
        "password, email, ",
        "realname, sex, mobile, ",
        "createtime, modifytime, ",
        "role_id)",
        "values (#{adminId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, ",
        "#{password,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ",
        "#{realname,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{mobile,jdbcType=VARCHAR}, ",
        "now(),now(), ",
        "#{roleId,jdbcType=INTEGER})"
    })
    int insert(BcAdmin record);

    @Insert({"insert into bc_admin (admin_id, username, ",
            "password, email, ",
            "realname, sex, mobile, ",
            "createtime, modifytime, ",
            "role_id)",
            "values (#{adminId,jdbcType=INTEGER}, #{username,jdbcType=VARCHAR}, ",
            "#{password,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, ",
            "#{realname,jdbcType=VARCHAR}, #{sex,jdbcType=INTEGER}, #{mobile,jdbcType=VARCHAR}, ",
            "now(),now(), ",
            "#{roleId,jdbcType=INTEGER})"})
    int insertAdmin(BcAdmin bcAdmin);

    @Select({
        "select",
        "admin_id, username, password, email, realname, sex, mobile, createtime, modifytime, ",
        "role_id",
        "from bc_admin",
        "where admin_id = #{adminId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="admin_id", property="adminId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="role_id", property="roleId", jdbcType=JdbcType.INTEGER)
    })
    BcAdmin selectByPrimaryKey(Integer adminId);

    @Select({
        "select",
        "admin_id, username, password, email, realname, sex, mobile, createtime, modifytime, ",
        "role_id",
        "from bc_admin"
    })
    @Results(id = "AdminMap",value = {
        @Result(column="admin_id", property="adminId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="username", property="username", jdbcType=JdbcType.VARCHAR),
        @Result(column="password", property="password", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR),
        @Result(column="sex", property="sex", jdbcType=JdbcType.INTEGER),
        @Result(column="mobile", property="mobile", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="role_id", property="roleId", jdbcType=JdbcType.INTEGER)
    })
    List<BcAdmin> selectAll();

    //根据电话查询
    @Select({
            "select",
            "admin_id, username, password, email, realname, sex, mobile, createtime, modifytime, ",
            "role_id",
            "from bc_admin",
            "where mobile=#{mobile}"
    })
    @ResultMap("AdminMap")
    BcAdmin selectByMobile(@Param("mobile")String mobile);
    //根据邮箱查询
    @Select({
            "select",
            "admin_id, username, password, email, realname, sex, mobile, createtime, modifytime, ",
            "role_id",
            "from bc_admin",
            "where role_id=#{roleId} and email=#{email}"
    })
    @ResultMap("AdminMap")
    BcAdmin selectByEmail(@Param("email")String email,@Param("roleId")Integer roleId);

    //根据邮箱查询
    @Select({
            "select",
            "admin_id, username, password, email, realname, sex, mobile, createtime, modifytime, ",
            "role_id",
            "from bc_admin",
            "where role_id=#{roleId} and username=#{username} "
    })
    @ResultMap("AdminMap")
    BcAdmin selectByUsername(@Param("username")String username,@Param("roleId")Integer roleId);

    //查询密码
    @Select({
            "select",
            "password",
            "from bc_admin",
            "where admin_id=#{adminId}"
    })
    @ResultMap("AdminMap")
    BcAdmin selectPassword(@Param("adminId")Integer adminId);
    //动态查询
    @SelectProvider(type = AdminBuildQuery.class,method = "QueryBuiler")
    @ResultMap("AdminMap")
    BcAdmin dynamicFind(@Param("bcAdmin") BcAdmin bcAdmin);

    @Update({
            "update bc_admin",
            "set username = #{username,jdbcType=VARCHAR},",
            "email = #{email,jdbcType=VARCHAR},",
            "realname = #{realname,jdbcType=VARCHAR},",
            "sex = #{sex,jdbcType=INTEGER},",
            "mobile = #{mobile,jdbcType=VARCHAR},",
            "modifytime = now(),",
            "role_id=#{roleId,jdbcType=INTEGER}",
            "where admin_id = #{adminId,jdbcType=INTEGER}"
    })
        int updateByPrimaryKey(BcAdmin record);

    //更新密码
    @Update({"update bc_admin",
            "set password=#{password,jdbcType=VARCHAR}",
            "where admin_id=#{adminId,jdbcType=INTEGER}"})
    int updatePassword(BcAdmin record);
}